<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/crm/layuiminiv2/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/crm/layuiminiv2/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" lay-filter="patform">
            <input type="hidden" name="pvid" >
            <input type="hidden" name="tid" >
            <div class="layui-form-item">
                <label class="layui-form-label required">患者id</label>
                <div class="layui-input-block">
                    <input type="text" name="patientid" lay-verify="required" lay-reqtext="患者id不能为空" placeholder="请输入患者id"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">患者姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="patientname" lay-verify="required" lay-reqtext="患者姓名不能为空" placeholder="请输入患者姓名"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" checked="">
                    <input type="radio" name="sex" value="女" title="女">
                    <input type="radio" name="sex" value="其他" title="其他">
                </div>
            </div>
            <div class="layui-form-item">
                    <label class="layui-form-label">出生日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="birthdate" id="birthdate" lay-verify="datetime" placeholder="yyyy-MM-dd hh:mm:ss" autocomplete="off" class="layui-input">
                    </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">城市</label>
                <div class="layui-input-block">
                    <select name="province" lay-filter="aihao" id="province">

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input type="text" name="address"   autocomplete="off" placeholder="请输入地址" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="contactphone" lay-verify="required|phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">分诊人</label>
                <div class="layui-input-block">
                    <input type="text" name="triageby" lay-verify="required" lay-reqtext="分诊人" placeholder="分诊人"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">分诊等级</label>
                <div class="layui-input-block">
                    <input type="text" name="acttriagelevel" lay-verify="required" lay-reqtext="分诊等级" placeholder="分诊等级"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">分诊时间</label>
                <div class="layui-input-block">
                    <input type="text" name="triagedt" id="triagedt" lay-verify="datetime" placeholder="yyyy-MM-dd hh:mm:ss" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="additional1" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="saveBtn">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/crm/layuiminiv2/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/crm/js/axios.min.js"></script>
<script>
    var pvid='${pvid}';
    console.log("当前pvid:"+pvid);
    if (pvid==undefined || pvid==null){
        pvid="";
    }
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            ,$ = layui.jquery
            , layer = layui.layer
            , laydate = layui.laydate;

        //出生日期
        laydate.render({
            elem: '#birthdate'
            ,type: 'datetime'
            ,value: '2023-01-01 00:00:00',
        });
        //分诊日期
        laydate.render({
            elem: '#triagedt'
            ,type: 'datetime'
            ,value: '2023-01-01 00:00:00',
        });
        //数据准备----
        axios({
            method: 'get',
            url: '/crm/dict/getDict?name=EDU_LEVEL',
            responseType: 'json'
        }).then(function (response) {
            var res = response.data.result;
            console.log("返回数据："+JSON.stringify(res));
            for (var a=0 ; a<res.length; a++)
            {
                var op= '<option value="'+res[a].dict_code+'">'+res[a].dict_name+'</option>';
                $("#province").append(op);
            }

        }).catch(function (error) {

        });
        //
        //监听提交
        form.on('submit(saveBtn)', function (data) {
          var index=  top.layer.msg("数据提交中，请稍后..",{icon:16,time:false,shade:0.8});
           var postData={};
            postData.triagePatient=data.field;
            postData.triageRecord=data.field;
            console.log("提交入参："+JSON.stringify(postData));
            //开始提交
            axios({
                method: 'post',
                url: '/crm/patient/savePatient',
                data: postData,
                responseType: 'json'
            }).then(function (response) {
                top.layer.close(index);
                var res = response.data;
                console.log("返回数据："+res);
                if (res.code==200){
                    top.layer.msg("操作成功！");
                    parent.location.reload();
                }else{
                    top.layer.msg("操作失败！"+res.msg);
                }
            }).catch(function (error) {
                top.layer.close(index);
                console.log(error);
                top.layer.msg("操作错误！"+error);
            });

            return false;//阻止表单默认行为
        });

        //表单初始赋值
        if (pvid!=''){
            axios({
                method: 'get',
                url: '/crm/patient/getPatientInfoByPvid?pvid='+pvid,
                //data: {pvid:pvid},
                responseType: 'json'
            }).then(function (response) {
                var res = response.data;
                console.log("返回数据："+JSON.stringify(res));
                form.val('patform',  res.result);
            }).catch(function (error) {

            });
        }

    });
</script>

</body>
</html>